

package MaintMenu.VenPricingUpdMasterFiles;

import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DEPO {

    public DEPO() {
        int cc=0;

        //create statement object
        SQLUpdStm stm = new SQLUpdStm();

        String tableA, tableB,onA,onB, whereA,whereB,whereoperator,
                fieldA1,fieldB1,
                fieldA2,fieldB2,
                fieldA3,fieldB3,
                fieldA4,fieldB4,
                fieldA5,fieldB5,
                fieldA6,fieldB6,
                fieldA7,fieldB7,
                fieldA8,fieldB8,
                fieldA9,fieldB9,
                fieldA10,field10;
        int filesToUpdate=1;

        while (filesToUpdate<=2){


            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String dataSourceName = "dbLI";
                String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
                Connection conli = DriverManager.getConnection(dbURL, "", "");


                String st[] = new String[3];



                 /* update mirror master file */
    //            whereA="WHERE A.CAPA=YES";
    //            whereB="B.CAPA=TRUE";
    //            whereoperator="AND";
                whereA="where a.depo_prc";
                whereB="b.[unit price]";
                whereoperator="<>";
                tableA =    "mirrorm1";
                tableB =    "_costdepo"+filesToUpdate;
                onA=        "partlink";
                onB=        "PartsLink1";

                fieldA1=    "part_no";       //part_no  (oem#)
                fieldB1=    "[OEM 1]";

                fieldA2=    "DEPO_NO";       //DEPOT #
                fieldB2=    "[DEPO NO]";

                fieldA3=    "DEPO_PRC";      //PRICE
                fieldB3=    "[UNIT PRICE]";

                fieldA4=    "DEPO_PKG";            //Package
                fieldB4=    "[Qty Ctn]";
                st[0] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3,fieldA4,fieldB4);
    //            System.out.println(st[0]);

                             /* update Cooling master file */
                whereA="where a.depo_prc";
                whereB="b.[unit price]";
                whereoperator="<>";
                tableA =    "coolngm";
                tableB =    "_costdepo"+filesToUpdate;
                onA=        "partlink";
                onB=        "PartsLink1";

                fieldA1=    "part_no";       //part_no  (oem#)
                fieldB1=    "[OEM 1]";

                fieldA2=    "DEPO_NO";       //DEPOT #
                fieldB2=    "[DEPO NO]";

                fieldA3=    "DEPO_PRC";      //PRICE
                fieldB3=    "[UNIT PRICE]";

                fieldA4=    "DEPO_PKG";            //Package
                fieldB4=    "[Qty Ctn]";
                st[1] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3,fieldA4,fieldB4);
    //            System.out.println(st[1]);

                 /* update LT_MAST11 master file */
                whereA="where a.depo_prc";
                whereB="b.[unit price]";
                whereoperator="<>";
                tableA =    "LT_MAST1";
                tableB =    "_costdepo"+filesToUpdate;
                onA=        "partlink";
                onB=        "PartsLink1";

                fieldA1=    "oem_no";       //part_no  (oem#)
                fieldB1=    "[OEM 1]";

                fieldA2=    "DEPO_NO";       //DEPOT #
                fieldB2=    "[DEPO NO]";

                fieldA3=    "DEPO_PRC";      //PRICE
                fieldB3=    "[UNIT PRICE]";

                fieldA4=    "DEPO_PKG";            //Package
                fieldB4=    "[Qty Ctn]";
                st[2] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3,fieldA4,fieldB4);
    //            System.out.println(st[2]);

                for (int x=0; x<st.length;x++){
                    Statement stli = conli.createStatement();

                    try {
//                        System.out.println("Script :"+st[x]);
                        int rowsupdated = stli.executeUpdate(st[x]);
                        System.out.print("TRU : "+rowsupdated+"\t");
                        //JOptionPane.showOptionDialog(null, "Statement : " + st[x] + "\n\nTotal record Updated : " + rowsupdated, "Update Complete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);

                        cc++;
                        if (cc==4){
                            System.out.println("");
                            cc=0;
                        }

                    }catch(SQLException er) {
                        er.printStackTrace();
                    }stli.close(); }
            }
            catch(Exception e){
                e.printStackTrace();
            }  filesToUpdate++;
        }
    }
}